from django.http import HttpResponse
from django.shortcuts import render
from TestModel.models import Test
from KerasCnn.use import keras_word
 
# 数据库操作
def new(request):
    test1 = Test(name='runoob')
    test1.save()
    return HttpResponse("<p>数据添加成功！</p>")

    
# 表单
def search_form(request):
    return render(request, 'search_form.html')
 
# 接收请求数据
def search(request):  
    request.encoding='utf-8'
    if 'q' in request.GET and request.GET['q']:
        message = '你搜索的内容为: ' + request.GET['q']
    else:
        message = '你提交了空表单'
    return HttpResponse(message)


def keras_demo(request):
    ctx ={}
    if request.POST:
        ctx['rlt'] = keras_word(request.POST['q'])
        
        test1 = Test(result=ctx['rlt'], name=request.POST['q'])
        test1.save()
    return render(request, "post.html", ctx)
